//
//  RootVCOfFair.m
//  ProjectA_ManualGuest
//
//  Created by dingcong on 16/6/14.
//  Copyright © 2016年 丁聪. All rights reserved.
//

#import "RootVCOfFair.h"
#import "Masonry.h"
#import "TittleView.h"
#import "FlowLayoutOfMeterial.h"
#import "VCOfMeterial.h"
#import "VCOfProduct.h"
#import "PrefixHeader.pch"
#import "CellOfchirldVC.h"
@interface RootVCOfFair ()<UICollectionViewDataSource, UICollectionViewDelegate, UIScrollViewDelegate>
@property(nonatomic, retain)TittleView *titleView;

@property(nonatomic, retain)UICollectionView *collection;

@end

@implementation RootVCOfFair



- (void)dealloc{
    [_collection release];
    [_titleView release];
    [super dealloc];
    
    
    
}
- (instancetype)init{
    if (self = [super init])
    {
        self.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"市集" image:[UIImage imageNamed:@"4.png"] tag:400];
        [self creatcollectionView];
    }
    return self;
    
    
    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithRed:0.0 / 256.0f  green:208.0 / 256.0f blue:252.0 / 256.0f alpha:1];
    
    [self creatTitleView];
    
    [self collectioncofig];
    [self.collection registerClass:[CellOfchirldVC class] forCellWithReuseIdentifier:@"pool"];
    
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBar.hidden = YES;
    
}


- (void)creatTitleView{
    
    
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    
    self.titleView = [[TittleView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 64)];
    self.titleView.backgroundColor = [UIColor colorWithRed:0.0 / 256.0f  green:208.0 / 256.0f blue:252.0 / 256.0f alpha:1];
    [self.view addSubview:self.titleView];
    
    [self.titleView release];

    
    
    self.titleView.arrOfTitle = @[@"成品", @"材料"];
    
    UIView *view = [[UIView alloc]init];
    
    view.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:view];
    
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleView.mas_top).offset(37);
        make.centerX.equalTo(self.titleView.mas_centerX);
        make.height.offset(19);
        make.width.offset(1);
        
        
        
    }];
    self.collection.dataSource = self;
    self.collection.delegate = self;
    
    [view release];
    
//    UIButton *buttonOfShoping = [UIButton buttonWithType:UIButtonTypeCustom];
//    buttonOfShoping.backgroundColor = [UIColor greenColor];
//    [buttonOfShoping setImage:[UIImage imageNamed:@"15.png"] forState:UIControlStateNormal];
//    [buttonOfShoping mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.titleView.mas_top).offset(5);
//        make.leading.equalTo(self.titleView.mas_leading).offset(5);
//        make.height.offset(20);
//        make.width.offset(20);
//        
//        
//    }];
//    [self.titleView addSubview:buttonOfShoping];
    
    
    
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    NSInteger index = scrollView.contentOffset.x / 2.0f / (CGRectGetWidth(self.view.bounds) / 2);
    
    
    for (UIButton *button in self.titleView.subviews) {
        
        [button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    }
    
    [self.titleView.subviews[index] setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    
    
    
    
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    
    return 2;
    
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
    CellOfchirldVC *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"pool" forIndexPath:indexPath];
    
    return cell;
    
    
}

- (void)creatcollectionView{
    
    FlowLayoutOfMeterial *layout = [[FlowLayoutOfMeterial alloc]init];
    
    
    layout.itemSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT);
    layout.minimumInteritemSpacing = 0;
    layout.minimumLineSpacing = 0;
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.collection = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64 - 49)collectionViewLayout:layout];
    
    
    self.collection.backgroundColor = [UIColor whiteColor];
    self.collection.dataSource = self;
    [self.view addSubview:self.collection];
}


- (void)collectioncofig{
    VCOfMeterial *meterial = [[VCOfMeterial alloc]init];
    
    
    
    VCOfProduct *product = [[VCOfProduct alloc]init];
    
    
    [self.collection addSubview:meterial.view];
    [self.collection addSubview:product.view];
    
    
    
    meterial.view.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds) - 113);
     [product.view mas_makeConstraints:^(MASConstraintMaker *make) {
         
         make.leading.equalTo(meterial.view.mas_trailing).offset(0);
         make.centerY.equalTo(meterial.view.mas_centerY);
         make.height.equalTo(meterial.view.mas_height);
         make.width.equalTo(meterial.view.mas_width);
         
     }];
    
    
    self.collection.pagingEnabled = YES;
    
    [self addChildViewController:meterial];
    [self addChildViewController:product];
    
    
}

- (UIStatusBarStyle)preferredStatusBarStyle{
    
    [super preferredStatusBarStyle];
    
    return UIStatusBarStyleLightContent;
    
}



@end
